package locality;

import tool.Utility;
import genome.Genotype;

public class CoSymbolicRegression {

	private Genotype g1;
	private Genotype g2;
	private int iFunc = 0;
	private double lower_bound = -1.0;
	private int nPoints =11;
	private double interval = 0.2;
	
	public static void main(String[] args) {
		
		
	}
	
	public CoSymbolicRegression(Genotype pG1, Genotype pG2, int pFunc, double pLower_bound, int pPoints, double pInterval){
		this(pG1,pG2,pFunc);
		this.lower_bound=pLower_bound;
		this.nPoints=pPoints;
		this.interval=pInterval;
	}
	
	public CoSymbolicRegression(Genotype pG1, Genotype pG2, int pFunc){
		this(pG1,pG2);
		this.iFunc = pFunc;
	}
	
	public CoSymbolicRegression(Genotype pG1, Genotype pG2){
		this.g1 = pG1.getCopy();
		this.g2 = pG2.getCopy();
	}
	
	public double CO1(){
		double[] x = symbolicValues(g1);
		double[] y = symbolicValues(g2);
		
		double[] m = Utility.mx(y);
		if(x[(int)m[1]]>m[0]){
			return 1.0;
		}
		else {
			return -1.0;
		}
		
	}

	public double[] symbolicValues(Genotype g) {
		
		double[] vals = new double[nPoints];
		double[] input = {lower_bound};
		for (int i = 0; i < vals.length; i++) {
			g.setInput(input);
			double v =Utility.roundToSignificantFigures(g.eval(),5); 
			if(Math.abs(v)<1.0E-12){ //added in to address machine error
				v = 0.0;
			}
			vals[i] = v;
			input[0] = input[0]+interval;
		}
		
		return vals;
	}

	public Genotype getG1() {
		return g1;
	}

	public void setG1(Genotype g1) {
		this.g1 = g1;
	}

	public Genotype getG2() {
		return g2;
	}

	public void setG2(Genotype g2) {
		this.g2 = g2;
	}

	public int getiFunc() {
		return iFunc;
	}

	public void setiFunc(int iFunc) {
		this.iFunc = iFunc;
	}
	
	

}
